<template>
  <div class="tuijian">
    <div class="swiper-container">
      <div class="swiper-wrapper">
        <div class="swiper-slide">
          <router-link :to="{name: 'lunbotu-xiangqing'}">
            <img src="../../assets/img/shouye/shouye/lunbo_xunli.png" alt="">
          </router-link>
        </div>
        <div class="swiper-slide">
          <router-link :to="{name: 'lunbotu-xiangqing'}"><img src="../../assets/img/shouye/shouye/lunbodazao.png"
                                                              alt="">
          </router-link>
        </div>
        <div class="swiper-slide">
          <router-link :to="{name: 'lunbotu-xiangqing'}">
            <img src="../../assets/img/shouye/shouye/lunbo_xunli.png" alt="">
          </router-link>
        </div>
        <div class="swiper-slide">
          <router-link :to="{name: 'lunbotu-xiangqing'}">
            <img src="../../assets/img/shouye/shouye/lunbodazao.png" alt="">
          </router-link>
        </div>
        <div class="swiper-slide">
          <router-link :to="{name: 'lunbotu-xiangqing'}">
            <img src="../../assets/img/shouye/shouye/lunbo_xunli.png" alt="">
          </router-link>
        </div>
      </div>
      <!-- 如果需要分页器 -->
      <div class="swiper-pagination"></div>
    </div>
    <h3>
      <img src="../../assets/img/shouye/shouye/laba.png" alt="">
      <router-link :to="{name: 'xinpin'}"><span>新品上市 促销大庆</span></router-link>
    </h3>
    <div class="xianshiduanhuo">
      <div class="duanhuo-left">
        <router-link :to="{name: 'xianshiduanhuo'}">
          <img src="../../assets/img/shouye/shouye/xianshiduanhuo.png" alt="">
        </router-link>
      </div>
      <div class="duanhuo-right">
        <div class="duanhuo-right-top">
          <router-link :to="{name: 'pinpaijingxuan'}">
            <img src="../../assets/img/shouye/shouye/jingpin.png" alt="">
          </router-link>
        </div>
        <div class="duanhuo-right-bottom">
          <router-link :to="{name: 'meishi-xiangqing'}">
            <img src="../../assets/img/shouye/shouye/chaozhiremai.png" alt="">
          </router-link>
        </div>
      </div>
    </div>
    <h6></h6>
    <h3>
      <img src="../../assets/img/shouye/shouye/rili.png" alt="">
      <span>今日推荐</span>
    </h3>
    <ul class="tuijian-ul">
      <li>
        <div class="jinrituijian">
          <router-link :to="{name: 'xuanliyanzhuang'}">
            <img src="../../assets/img/shouye/shouye/lunbo_xunli.png" alt="">
          </router-link>
        </div>
        <ul class="shangpin-ul">
          <li v-for="good in Arr">
            <router-link :to="{name: 'shangpinxiangqing', params: {good}}">
              <div>
                <img @click="toSP()" :src="good.src" alt="">
              </div>
            </router-link>
            <h5>{{good.name}}</h5>
            <span>¥59</span>
          </li>
        </ul>
      </li>
    </ul>
    <div class="up" @click="toTop()" v-if="isUP">
      <img src="../../assets/img/shouye/tuijian-xuanliyanzhuang/toTop.png"/>
    </div>
  </div>
</template>
<script>
  import * as $ from 'jquery'
  import * as Swiper from 'swiper'
  import "swiper/dist/css/swiper.css"
  import '../../style/mySwiper.css'
  import Vue from 'vue'
  //  import * as BootStrap from 'bootstrap'
 export default {
    data () {
      return {
        isUP: false,
        Arr: []
      }
    },
    mounted() {
      new Swiper['default']('.swiper-container', {
        loop: true,
        autoplay: true,
        // 如果需要分页器
        pagination: {
          el: '.swiper-pagination',
          clickable: true,
          bulletActiveClass: 'my-bullet-active',
        },
      }),
        window.addEventListener('scroll', this.menu)
    },
    methods: {
      toTop () {
        if(document.documentElement){
          document.documentElement.scrollTop = 0;
        }else{
          document.body.scrollTop = 0;
        }
      },
      menu() {
        this.scroll = document.documentElement.scrollTop || document.body.scrollTop;
        if(this.scroll > 0){
          //显示 a 标签
          this.isUP = true;
        }else{
          //隐藏 a 标签
          this.isUP = false;
        };
      },
      top () {
        window.scrollTo(0,0);
      },
      toSP () {
//        this.$router.push({name: 'shangpinxiangqing', params: {good}})
      },
      tuijianGet() {
        //  发起get请求
        //  设置代理服务器转发的域
        Vue.axios.get('/api/get', {
//              get传递的query参数
//            params: {
//              name: 'along',
//              age: 32
//            }
        }).then( (response) => {
          //  成功之后的回调
//          console.log(response.data);
          this.Arr = response.data;
//          console.log(this.Arr);
        }).catch( (error) => {
          //  请求出错的处理
          console.log(error)
        });
      }
    },
    created(){
     this.top();
    },
   mounted () {
     this.tuijianGet();
   }
  }
</script>
<style scoped>
  /*@import url("../../../node_modules/swiper/dist/css/swiper.css");*/
  /*@import url("../../../node_modules/bootstrap/dist/css/bootstrap.css");*/
  .tuijian {
    margin-top: 2rem;
    padding-bottom: 3rem;
    position: relative;
    width: 100%;
  }

  .swiper-container {
    background: #f2f2f2;
  }

  .swiper-slide img {
    width: 100%;
  }

  .tuijian h6 {
    width: 100%;
    height: 0.4rem;
    background: #f2f2f2;
  }

  .tuijian h3 {
    margin: 0;
    padding-left: 0.5rem;
    border-bottom: 1px solid #ccc;
  }

  .tuijian h3 img {
    width: 0.8rem;
    vertical-align: middle;
  }

  .tuijian h3 span {
    font-family: MicrosoftYaHei;
    font-size: 0.8rem;
    font-weight: normal;
    font-stretch: normal;
    line-height: 1rem;
    letter-spacing: 0rem;
    color: #4d4d4d;
  }

  .tuijian .xianshiduanhuo {
    width: 100%;
    display: flex;
    border-bottom: 1px solid #cccccc;
    padding-top: 0.2rem;
  }

  .tuijian .duanhuo-left {
    text-align: center;
    flex: 1;
  }

  .tuijian .duanhuo-left img {
    width: 6rem;
    font-size: 0;
  }

  .tuijian .duanhuo-right {
    text-align: center;
    flex: 1;
  }

  .tuijian .duanhuo-right-top {
    border-bottom: 1px solid #cccccc;
  }

  .tuijian .duanhuo-right img {
    width: 6rem;
    font-size: 0;
  }

  .tuijian-ul {
    border-bottom: 1px solid #ccc;
  }

  .jinrituijian img {
    width: 100%;
  }

  .shangpin-ul {
    width: 100%;
    margin-left: 0.1rem;
    margin-bottom: 0.2rem;
  }

  .shangpin-ul > li {
    width: 5rem;
    display: inline-block;
    text-align: center;
    border: 1px solid #ccc;
    margin: 0.1rem;
  }

  .shangpin-ul > li div {
    text-align: center;
    width: 4rem;
    height: 4rem;
    margin: 0 auto;
    padding-top: 1rem;
  }
  .shangpin-ul > li div img {
    max-width: 4rem;
    max-height: 3rem;
  }
  .shangpin-ul > li h5 {
    font-size: 0.6rem;
  }

  .shangpin-ul > li span {
    display: block;
    font-size: 0.6rem;
    color: #e83d41;
  }

  .up {
    width: 1.5rem;
    position: fixed;
    bottom: 3rem;
    right: 0.3rem;
  }
  .up img {
    width: 100%;
  }
</style>
